package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.DateUtil;
import com.alibaba.druid.support.json.JSONUtils;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Getter
@Setter
public class Travel {

    public static final int STATE_REJECT = 0;   //拒绝
    public static final int STATE_NORMAL = 1;   //草稿
    public static final int STATE_WAITING = 2;  //待审核
    public static final int STATE_RELEASE = 3;  //审核通过/发布

    private Long id;

    private String title;   //标题

    @JsonFormat(pattern = "yyyy-MM-dd ",timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date travelTime;    //旅行时间

    private String perExpends;  //消费

    private Integer days;   //旅行天数

    private Integer person; //和谁

    private User author; //作者

    @JsonFormat(pattern = "yyyy-MM-dd ",timezone = "GMT+8")
    private Date createTime;    //创建时间

    @JsonFormat(pattern = "yyyy-MM-dd ",timezone = "GMT+8")
    private Date releaseTime;   //发布时间

    private Boolean isPublic;   //是否公开

    private Region place;  //地区

    private String coverUrl;    //封面

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private Date lastUpdateTime;    //最后更新时间

    private Integer state = STATE_NORMAL;  //状态

    //游记与内容是一对一关系,id相同,分表操作提升性能
    private TravelContent travelContent;


    public String getStateDisplay(){
        if(state==STATE_REJECT){
            return "审核拒绝";
        }else if(state==STATE_NORMAL){
            return "草稿";
        }else if(state==STATE_WAITING){
            return "待审核";
        }else{
            return "发布";
        }
    }

    public String getJsonString(){
        Map<String, Object> map = new HashMap<>();
        map.put("id",id);
        map.put("title",title);
        map.put("coverUrl",coverUrl);
        return JSONUtils.toJSONString(map);
    }
}